package com.example.myapplication.ui.fragment;

import android.content.Intent;
import android.os.Parcelable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;

import com.example.myapplication.R;
import com.example.myapplication.base.BaseLazyFragment;
import com.example.myapplication.bean.HomesBanner;
import com.example.myapplication.bean.HomesListBean;
import com.example.myapplication.bean.SquaseBean;
import com.example.myapplication.presenter.HomesPresenter;
import com.example.myapplication.ui.activity.WebViewActivity;
import com.example.myapplication.ui.adapter.HomesAdapter;
import com.example.myapplication.ui.adapter.SquareAdapter;
import com.example.myapplication.view.HomesView;

import java.util.List;


public class HomesFragment extends BaseLazyFragment<HomesPresenter> implements HomesView {

    private RecyclerView rv;
    private HomesAdapter homesAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getHomesData();//banner
        mPresenter.getHomesList();//list
    }

    @Override
    protected void initView(View view) {
        rv = (RecyclerView) view.findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        homesAdapter = new HomesAdapter(getContext());
        rv.setAdapter(homesAdapter);
        homesAdapter.setOnItemClickListener(new HomesAdapter.OnItemClickListener() {
            @Override
            public void OnItemClick(int position, List<HomesListBean.DataBean.DatasBean> list) {
                Intent intent = new Intent(getContext(), WebViewActivity.class);
                intent.putExtra("like",list.get(position).getLink());
                startActivity(intent);
            }
        });
     }

    @Override
    protected HomesPresenter initPresenter() {
        return new HomesPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_homes;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    //banner
    @Override
    public void setData(HomesBanner homesBanner) {
        List<HomesBanner.DataBean> data = homesBanner.getData();
        Log.d(TAG, "setData: "+data);
        homesAdapter.setBannerList(data);
    }

    //list
    @Override
    public void setListData(HomesListBean homesListBean) {
        List<HomesListBean.DataBean.DatasBean> datas = homesListBean.getData().getDatas();
        homesAdapter.setList(datas);
    }

    private static final String TAG = "HomesFragment";
}